package com.znzz.course.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.znzz.course.entity.Course;
import com.znzz.course.R;

/**
 * 课的详细信息查看
 * @Author by DHF
 * @Date 2022/04/2022/4/13 22:05
 * @Version 1.0
 */
public class MessageCourseActivity extends AppCompatActivity {
    private TextView inputCourseName,inputTeacher,inputClassRoom,inputDay,inputTime,inputWeek,remark_information;
    private Button backButton,insert_remark;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_update_course);
        //点击对话框是否消失
        setFinishOnTouchOutside(false);
        //初始化控件
        initView();

        Intent intent = getIntent();
        Course course = (Course) intent.getSerializableExtra("course");
        inputCourseName.setText(course.getCourseName());
        inputTeacher.setText(course.getTeacher());
        inputClassRoom.setText(course.getClassRoom());
        inputDay.setText("周" +getDayString(course.getDay()));
        inputTime.setText(course.getClassStart()+"-" + course.getClassEnd()+ "节");
        inputWeek.setText(course.getWeekStart()+"-"+course.getWeekEnd()+"周");
        remark_information.setText(course.getRemark()+" ");
        //返回主页面
        backButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        //添加备注信息
        insert_remark.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MessageCourseActivity.this, RemarkActivity.class);
                intent.putExtra("className",inputCourseName.getText().toString());
                startActivityForResult(intent, 0);
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (resultCode){
            case 1:
                Intent intent = new Intent(MessageCourseActivity.this, MainActivity.class);
                startActivityForResult(intent,4);
                finish();
                break;
            default:
                break;
        }
    }

    //由数字星期得出文字星期
    static public String getDayString(int day) {
        String dayString;
        switch (day){
            case 1:
                dayString = "一";
                break;
            case 2:
                dayString = "二";
                break;
            case 3:
                dayString = "三";
                break;
            case 4:
                dayString = "四";
                break;
            case 5:
                dayString = "五";
                break;
            case 6:
                dayString= "六";
                break;
            case 7:
                dayString= "日";
                break;
            default:
                dayString= "";
                break;
        }
        return dayString;
    }

    public void initView(){
        inputCourseName = (TextView) findViewById(R.id.course_name);
        inputTeacher = (TextView) findViewById(R.id.teacher_name);
        inputClassRoom = (TextView) findViewById(R.id.class_room);
        inputDay = (TextView) findViewById(R.id.day);
        inputTime = (TextView) findViewById(R.id.time_information);
        inputWeek = findViewById(R.id.week_information);
        backButton = (Button) findViewById(R.id.button);
        remark_information = findViewById(R.id.remark_information);
        insert_remark = findViewById(R.id.insert_remark);
    }
}

